<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ page import="java.io.*" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    Map<String, Map<String, List<String>>> targetMap = (Map<String, Map<String, List<String>>>) session.getAttribute("allowData");
    String[] in = {"monitsite", "surface", "line", "dot", "water", "tool", "catches", "fish", "fishEgg", "zooplankton", "phytoplankton", "benthos", "zooplanktonSpecies", "phytoplanktonSpecies", "benthosSpecies"};
    String[] Name = {"监测点", "断面", "侧线", "测点", "采样水层", "网具", "渔获物", "渔样本", "卵样本", "浮游动物", "浮游植物", "底栖生物", "浮游动物优势种", "浮游植物优势种", "底栖生物优势种"};
    List<String> index = Arrays.asList(in);
    Map<String, List<String>> map = null;
%>

<%!
        private Map<String, String> photomap = new HashMap<String, String>();

        private String writeTd(int t, List<String> messageList, boolean havePhoto) {
            StringBuilder buffer = new StringBuilder();
            int add = 0;
            if (t == -1) {
                t = 1;
                add = 1;
            } else if (t == -2) {
                add = 1;
                t = 0;
            } else if (t == -3) {
                t = 1;
                add = -1;
            } else if (t == -4) {
                t = 0;
                add = -1;
            }
            for (int j = 0; j <= messageList.size() - 1; j++) {
                String[] message = (messageList.get(j)).split(",");
                buffer.append("<tr>");
                // System.out.println("length = "+message.length+"     "+message.toString());
                for (int k = 1; k <= message.length - 1 + add; k++) {
                    if (k == t + 1) continue;
                    System.out.println(message[k] + "   " + k);
                    buffer.append("<td>").append(message[k]).append("</td>");
                }
                if(havePhoto){
                    buffer.append("<td><button style = \"margin-top:5px\"" + " name=\"").append(message[t + 1]).append("\" id=\"").append(message[0]).append("\" class=\" btn1 btn-primary \">查看</button></td>");
                    photomap.put(message[0],message[t+1]);
                }
                buffer.append("</tr>");
            }
            System.out.println("aaaaaaaaaa"+photomap);
            return buffer.toString();
        }
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>My JSP 'showRequestData.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <link href="css/register.css" rel="stylesheet"/>
    <link href="css/main.css" rel="stylesheet"/>
    <link href="css/jstree.min.css" rel="stylesheet"/>
    <link href="css/cysc.css" rel="stylesheet"/>
    <link href="css/show.css" rel="stylesheet"/>
    <link rel="stylesheet" href="font-awesome/css/font-awesome.min.css">
    <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="js/showRequestPhoto.js"></script>
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <style>
        h2 {
            height: 60px;
            line-height: 60px;
            border-bottom: 1px solid gray;
        }

        #showAll button {
            display: none;
        }
    </style>
</head>

<body>
<div id="showAll" class="hideView">
    <%@ include file="showPhotoView.jsp" %>
</div>
<div style="overflow-y:auto;padding: 20px;margin-bottom: 120px;">
    <%
        Set<String> targetName = targetMap.keySet();
        for (String p : targetName) {
            out.write("<h2>" + p + "</h2><br>");
            map = targetMap.get(p);
            Object[] tableName = (map.keySet()).toArray();
            for (int i = 0; i <= tableName.length - 1; i++) {
                String name = (String) tableName[i];
                int x = index.indexOf(name.trim());
                switch (x) {
                    case 0:
    %>
    <h3><%= Name[x]%>:</h3>
    <div style="overflow-x:auto;">
        <table class="table" style="margin: 0px;margin-top: 10px;margin-bottom: 10px;width: 2000px;">
            <tr>
                <th>监测单位</th>
                <th>检测人员</th>
                <th>日期</th>
                <th>详细地点</th>
                <th>水域</th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>起点经度</th>
                <th>起点纬度</th>
                <th>终点经度</th>
                <th>终点纬度</th>
                <th>天气</th>
                <th>温度</th>
                <th>照片</th>
            </tr>
            <%
                List<String> messageList = map.get(name);
                for (int j = 0; j <= messageList.size() - 1; j++) {
                    String[] message = (messageList.get(j)).split(",");
                    out.write("<tr>");
                    photomap.put(message[0], message[6]);
                    for (int k = 1; k < message.length - 1; k++) {
                        if (k == 6) continue;
            %>
            <td><%=message[k]%>
            </td>
            <%
                    }
                    out.write("<td><button name=\"" + message[6] + "\" id=\"" + message[0] + "\" class=\" btn1 btn-primary \">查看</button></td>");
                    out.write("</tr>");
                }

            %>
        </table>
    </div>
    <%
            break;
        case 1:
    %>
    <h3><%= Name[x]%>:</h3>
    <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
        <tr>
            <th>采样方位</th>
            <th>距岸距离</th>
        </tr>
        <%
            List<String> te = map.get(name);
            out.write(writeTd(2, te, false));
        %>
    </table>

    <%
            break;
        case 2:
    %>
    <h3><%= Name[x]%>:</h3>
    <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
        <tr>
            <th>起点经度</th>
            <th>起点纬度</th>
            <th>终点经度</th>
            <th>终点纬度</th>
        </tr>
        <%
            out.write(writeTd(4, map.get(name), false));
        %>
    </table>
    <%
            break;
        case 3:
    %>

    <h3><%= Name[x]%>:</h3>
    <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
        <tr>
            <th>经度</th>
            <th>纬度</th>
        </tr>
        <%
            out.write(writeTd(2, map.get(name), false));
        %>
    </table>

    <%
            break;

        case 4:
    %>
    <h3><%= Name[x]%>:</h3>
    <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
        <tr>
            <th>位置</th>
            <th>深度</th>
            <th>温度</th>
            <th>水位</th>
            <th>流量</th>
        </tr>
            <%
                 out.write(writeTd(5,map.get(name),false));
                 out.write("</table>");
                 break;
                 
                 case 5:
                 %>
        <h3><%= Name[x]%>:</h3>
        <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
            <tr>
                <th>名称</th>
                <th>网型</th>
                <th>网口面积</th>
                <th>网口倾角</th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>网口流量</th>
                <th>照片</th>
            </tr>
                <%
                 List<String> list = map.get(name);
                 out.write(writeTd(0,list,true));
                 out.write("</table>");
                 break;
                 
                 case 6:
                 %>
            <h3><%= Name[x]%>:</h3>
            <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
                <tr>
                    <th>鱼类名称</th>
                    <th>卵苗总数</th>
                    <th>鱼卵数</th>
                    <th>幼鱼数</th>
                    <th>照片</th>
                </tr>
                    <%
                 out.write(writeTd(-3,map.get(name),true));
                 out.write("</table>");
                 break;
                 
                 case 7:
                 %>
                <h3><%= Name[x]%>:</h3>
                <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
                    <tr>
                        <th>体长</th>
                        <th>全长</th>
                        <th>体重</th>
                        <th>年龄</th>
                        <th>鱼获得ID</th>
                        <th>照片</th>
                    </tr>
                        <%
                 out.write(writeTd(0,map.get(name),true));
                 out.write("</table>");
                 break;
                 
                 case 8:
                 %>
                    <h3><%= Name[x]%>:</h3>
                    <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
                        <tr>
                            <th>发育期</th>
                            <th>鱼卵卵径</th>
                            <th>鱼卵卵膜径</th>
                            <th>色素性状</th>
                            <th>胚胎性状</th>
                            <th>鱼获得ID</th>
                            <th>照片</th>
                        </tr>
                            <%
                 out.write(writeTd(0,map.get(name),true));
                 out.write("</table>");
                 break;
                 
                 case 9:
                 %>
                        <h3><%= Name[x]%>:</h3>
                        <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
                            <tr>
                                <th>生物量</th>
                                <th>数量</th>
                                <th>照片</th>
                            </tr>
                                <%
                 out.write(writeTd(-4,map.get(name),true));
                 out.write("</table>");
                 break;
                 
                 case 10:
                 %>
                            <h3><%= Name[x]%>:</h3>
                            <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
                                <tr>
                                    <th>生物量</th>
                                    <th>数量</th>
                                    <th>照片</th>
                                </tr>
                                    <%
                 out.write(writeTd(-4,map.get(name),true));
                 out.write("</table>");
                 break;
                 
                 case 11:
                 %>
                                <h3><%= Name[x]%>:</h3>
                                <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
                                    <tr>
                                        <th>生物量</th>
                                        <th>数量</th>
                                        <th>照片</th>
                                    </tr>
                                        <%
                 out.write(writeTd(-4,map.get(name),true));
                 out.write("</table>");
                 break;
                 
                 case 12:
                 %>
                                    <h3><%= Name[x]%>:</h3>
                                    <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
                                        <tr>
                                            <th>名称</th>
                                            <th>生物量</th>
                                            <th>数量</th>
                                            <th>照片</th>
                                        </tr>
                                            <%
                 out.write(writeTd(-3,map.get(name),true));
                 out.write("</table>");
                 break;
                 
                 case 13:
                 %>
                                        <h3><%= Name[x]%>:</h3>
                                        <table class="table" style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
                                            <tr>
                                                <th>名称</th>
                                                <th>生物量</th>
                                                <th>数量</th>
                                                <th>照片</th>
                                            </tr>
                                                <%
                 out.write(writeTd(-3,map.get(name),true));
                 out.write("</table>");
                 break;
                 
                 case 14:
                 %>
                                            <h3><%= Name[x]%>:</h3>
                                            <table class="table"
                                                   style="margin-top: 10px;margin-bottom: 10px;width: 100%;">
                                                <tr>
                                                    <th>名称</th>
                                                    <th>生物量</th>
                                                    <th>数量</th>
                                                    <th>照片</th>
                                                </tr>
                                                    <%
                 out.write(writeTd(-3,map.get(name),true));
                 out.write("</table>");
                 break;
                 
                 
                 
                 
              }
      }
     }
    
    %>
</div>
</body>
</html>
